<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Hello, world!</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/font-awesome.min.css">
    <link rel="stylesheet" href="../fonts/iconfont.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-select.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }

        html,
        body {
            height: 100%;
        }

        body {
            padding-bottom: 40px;
            background-color: #fff;
        }

        .form-signin {
            width: 100%;
            max-width: 640px;
            margin: auto;
            padding: 15px;
        }

        .form-signin .checkbox {
            font-weight: 400;
        }

        .form-signin .form-control {
            position: relative;
            box-sizing: border-box;
            height: auto;
            padding: 10px;
            font-size: 16px;
        }
        .form-control-theme{
            border: none !important;
            border-bottom: none !important;
           
        }
        .form-select{
            background-color: transparent !important;
        }

        .form-signin .form-control:focus {
            z-index: 2;
        }

        .form-signin input[type="email"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }

        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }

        .sr-only2 {
            margin-top: 15px;
        }


        .logodiv img {
            width: 220px;
            height:80px ;
            margin: 0 auto;
            display: block;
        }

        .logodiv {
            text-align: center;
        }




        .fgtpaws {
            text-align: center;
            margin-top: 10px;
        }

        .btn {
            padding: 0.375rem 0.15rem
        }

        .btn-tiqu {
            width: 125px;
            margin: 0 auto;
            display: block;
        }

        .buytitle {
            font-size: 1.1rem;
            color: #03357a;
            margin-top: 20px;
        }

        .buytitle span {
            font-size: 1rem;
            color: #999;
        }
        .action-row button {
            margin-bottom: 15px;
        }

        .buysearch {
            font-size: smaller;
        }

        .formscreen .form-control-theme {
            font-size: smaller;
        }

        .action-row {
            position: fixed;
            width: 100%;
            bottom: 0;
            margin-top: 0;
            margin-bottom: 0;
            background: #fff;
            left: 0;
        }
        .wareContent{
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
        }
        #app{
            height: 100vh;
            overflow: hidden;
        }
        .container2 {
            padding:10px;
            display: block;
            height: 100% !important;
            overflow: hidden !important;
        }
        .lineCss{
            width: 90%;
            margin: 0 auto;
            font-size: 0.8rem;
            padding: 20px 20px;
            
        }
        .lineBorder{
            width: 90%;
            margin: 0 auto;
            font-size: 0.8rem;
            padding: 20px 20px;
            border-bottom: 1px solid #000;
        }
        .bootstrap-select {
            width: calc(100% - 0px) !important;
        }

        .formscreen .filter-option-inner-inner {
            font-size: smaller;
        }

        .myselect {
            width: calc(100% - 0px);
        }

        .btn-action:disabled {
            background: #D9D9DA !important;
            color: #808081 !important;
        }

        .buysearch {
            width: 100%;
            display: block;
        }
        .item-border{
            border-bottom: 1px solid #ced4da;
            margin-bottom: 2px;
        }
        
    </style>
</head>

<body>
    <div id="app">
        <div class="container2">
            <!-- <div class="logodiv">
                <img class="bannerlogo" src="../image/logo.jpeg">
            </div> -->
            <div class="row">
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh  flex-shrink-0 filedlabel">{{lan['Issue_Date']}}
                        </div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <input type="date" v-model="searchdata.ArrivedDate"
                                placeholder="Please Enter Issue Date(Required)"
                                class="form-control form-control-theme" value="">
                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Part']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input
                                @blur="blurPartNumInfo"
                                type="text"
                                v-model="searchdata.PartNum"
                                class="form-control form-control-theme" value="">
                            </div>

                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Desc']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input
                                type="text"
                                disabled
                                v-model="searchdata.PartDescription"
                                class="form-control form-control-theme" value="">
                            </div>

                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['From_WarehouseCode']}}
                        </div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input   v-if="!searchdata.warehouseFlag" type="text"
                                v-model="searchdata.FromWarehouseCode"
                                @click="warehouseFocus()"
                                class="form-control form-control-theme" value="">

                                <select  v-if="searchdata.warehouseFlag" v-model="searchdata.FromWarehouseCode" id="vendorselect"
                                :placeholder="lan['WareHouseCode_placeholder']"
                                @change="waerChange()"
                                class="form-select myselect myselect1 form-control-theme"
                                data-live-search="true">
                                    <option v-for="(item,index) in WareHouseCodeList" :key="index"
                                        :data-num="item.Warehse_WarehouseCode" :value="item.Warehse_WarehouseCode"
                                        :data-name="item.Warehse_Description" :data-tokens="item.Warehse_WarehouseCode">
                                        {{item.Warehse_Description}}</option>
                                </select>
                                <i v-if="!searchdata.warehouseFlag" style="margin-left: 5px;" @click="onWareQuery()" class="iconfont icon-scan"></i>
                                <i v-if="searchdata.warehouseFlag" style="margin-left: 5px;" @click="onWareScan()" class="iconfont icon-query"></i>
                            </div>
                          
                        </div>
                    </div>
                </div>


                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['From_BinNum']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input   v-if="!searchdata.binFlag" type="text"
                                @click="binFocus()"
                                v-model="searchdata.FromBinNum"
                                class="form-control form-control-theme" value="">
                                <select v-if="searchdata.binFlag" v-model="searchdata.FromBinNum" id="vendorselect2"
                                @change="binChange()" 
                                class="form-select myselect myselect2 form-control-theme"
                                data-live-search="true" :placeholder="lan['BinNum_placeholder']">
                                <option v-for="(item,index) in BinNumList" :key="index" :data-num="item.WhseBin_BinNum"
                                    :value="item.WhseBin_BinNum" :data-name="item.WhseBin_Description"
                                    :data-tokens="item.WhseBin_BinNum">
                                    {{item.WhseBin_Description}}</option>
                                </select>
                                <i  v-if="!searchdata.binFlag" style="margin-left: 5px;" @click="onBinQuery()" class="iconfont  icon-scan"></i>
                                <i  v-if="searchdata.binFlag" style="margin-left: 5px;" @click="onBinScan()" class="iconfont icon-query"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div v-if="searchdata.is_Lot" class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel" style="word-wrap: break-word;">{{lan['Lot']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input  type="number"
                                v-if="searchdata.lotFlag"
                                @blur="lotBlur()"
                                :disabled="Lot_btn"
                                v-model="searchdata.LotNum"
                                class="form-control form-control-theme" value="">
                                <input  type="number"
                                v-if="!searchdata.lotFlag"
                                :disabled="Lot_btn"
                                @click="lotFocus()"
                                v-model="searchdata.LotNum"
                                class="form-control form-control-theme" value="">
                                <i  v-if="!searchdata.lotFlag" style="margin-left: 5px;" @click="onLotQuery()" class="iconfont  icon-scan"></i>
                                <i  v-if="searchdata.lotFlag" style="margin-left: 5px;" @click="onLotScan()" class="iconfont icon-query"></i>

                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel" style="word-wrap: break-word;">{{lan['Onhand_Qty']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input type="text" 
                                disabled
                                v-model="searchdata.OnhandQty" class="form-control form-control-theme"
                                value="">
                                <input 
                                v-if="searchdata.IUM"
                                style="width: 25px;text-align: center;"
                                type="text" 
                                v-model="searchdata.IUM" class="form-control form-control-theme"
                                value="">
                            </div>
                            
                        </div>
                    </div>
                </div>

                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel" style="word-wrap: break-word;">{{lan['Tran_Qty']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input type="text" 
                                v-model="searchdata.TranQty" class="form-control form-control-theme"
                                value="">
                                <div  v-if="searchdata.is_SerialNum">
                                    <button style="width: 80px;"  type="button" tapmode="" @click="toSerial()" :disabled="!searchdata.is_SerialNum"
                                        :class=" searchdata.is_SerialNum == false ? 'btn-secondary':'btn-primary'"
                                        class="btn btn-primary  btn-block">{{lan['Serial_No']}}
                                        <span class="badge badge-light">{{searchdata.SerialNum.length}}</span>
                                    </button>
                                </div>
                            </div>
                            
                        </div>
                    </div>
                </div>
             
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['To_WarehoseCode']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input   v-if="!searchdata.warehouseFlag1" type="text"
                                v-model="searchdata.ToWarehoseCode"
                                @click="houseFocus()"
                                class="form-control form-control-theme" value="">
                                <select v-if="searchdata.warehouseFlag1" v-model="searchdata.ToWarehoseCode" id="vendorselect3"
                                @change="housechange()" :placeholder="lan['WareHouseCode_placeholder']"
                                class="form-select myselect myselect3 form-control-theme"
                                data-live-search="true">
                                <option v-for="(item,index) in WareHouseCodeList" :key="index"
                                    :data-num="item.Warehse_WarehouseCode" :value="item.Warehse_WarehouseCode"
                                    :data-name="item.Warehse_Description" :data-tokens="item.Warehse_WarehouseCode">
                                    {{item.Warehse_Description}}</option>
                                </select>
                                <i v-if="!searchdata.warehouseFlag1" style="margin-left: 5px;" @click="onWareQuery1()" class="iconfont icon-scan"></i>
                                <i v-if="searchdata.warehouseFlag1" style="margin-left: 5px;" @click="onWareScan1()" class="iconfont icon-query"></i>
                            </div>
                           
                        </div>
                    </div>
                </div>


                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['To_BinNum']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input   v-if="!searchdata.binFlag1" type="text"
                                @click="binFocus1()"
                                v-model="searchdata.ToBinNum"
                                class="form-control form-control-theme" value="">
                                <select  v-if="searchdata.binFlag1" v-model="searchdata.ToBinNum" id="vendorselect4"
                                class="form-select myselect myselect4 form-control-theme"
                                data-live-search="true" :placeholder="lan['BinNum_placeholder']">
                                <option v-for="(item,index) in bin" :key="index" :data-num="item.WhseBin_BinNum"
                                    :value="item.WhseBin_BinNum" :data-name="item.WhseBin_Description"
                                    :data-tokens="item.WhseBin_BinNum">
                                    {{item.WhseBin_Description}}</option>
                                </select>
                                <i  v-if="!searchdata.binFlag1" style="margin-left: 5px;" @click="onBinQuery1()" class="iconfont  icon-scan"></i>
                                <i  v-if="searchdata.binFlag1" style="margin-left: 5px;" @click="onBinScan1()" class="iconfont icon-query"></i>
                            </div>
                        </div>
                    </div>
                </div>

              

            </div>

            <div class=" row justify-content-center" style="padding:10px;">
                <div style="padding-left: 5px;padding-right: 5px;" class="col-3 col-md-3">
                    <button type="button" onclick="scan();" tapmode=""
                        class="btn btn-primary btn-action">{{lan['Scan']}}
                    </button>
                </div>
                <div style="padding-left: 5px;padding-right: 5px;" class="col-3 col-md-3">
                    <button type="button" :disabled="receipt_btn" onclick="checksubmit();" tapmode=""
                        class="btn btn-primary btn-action">{{lan['Confirm']}}</button>
                </div>
                <div style="padding-left: 5px;padding-right: 5px;" class="col-3 col-md-3">
                    <button type="button" :disabled="reset_btn" onclick="Resetsubmit();" tapmode=""
                        class="btn btn-primary btn-action">{{lan['Reset']}}</button>
                </div>

                <div style="padding-left: 5px;padding-right: 5px;" class="col-3 col-md-3">
                    <button type="button" tapmode="" onclick="close_win1()"
                        class="btn btn-primary btn-action">{{lan['Cancel']}}</button>
                </div>

            </div>
            <div class="copyright">
                <div class="row" :gutter="10">
                    <div  class="col-5" style="text-align: right;">{{lan['Version']}}：</div>
                    <div  class="col-7">{{appVersion}}</div>
                    <div  class="col-5"  style="text-align: right;">{{lan['Site']}}：</div>
                    <div  class="col-7">{{SiteName}}</div>
                    <div  class="col-5"  style="text-align: right;">{{lan['Company']}}：</div>
                    <div  class="col-7">{{CompanyName}}</div>
                </div>
            </div>
        </div>
    </div>

</body>
<script type="text/javascript" src="../script/lang.js"></script>
<script type="text/javascript" src="../script/model.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="../script/bootstrap-select.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    var postcount = 0;
    var tagspostcount = 0;
    var returncount = 0;
    var model_show = 1;
    var postlist = [];
    var tags = [];
    const app = new Vue({
        el: '#app',
        data: {
            lineCss:"lineCss",
            lineBorder:'lineBorder',
            list: [],
            newList:[],
            screenwidth: document.body.clientWidth,
            house: [],
            bin: [],
            WareHouseCodeList:[],
            BinNumList:[],
            BinNum: "",
            searchdata: {
                name: '',
                PartDescription:'',
                PartNum:'',
                FromWarehouseCode:'',
                FromBinNum:'',
                ToWarehoseCode:'',
                ToBinNum:'',
                ArrivedDate: timenow(),
                LotNum:'',
                OnhandQty:"",
                TranQty:"",
                IUM:'',
                oldQty:"",
                is_Lot:false,
                is_SerialNum:false,
                SerialNum:[],
                lotFlag:false,
                binFlag:false,
                warehouseFlag:false,
                binFlag1:false,
                warehouseFlag1:false,
                PartClass_NegQtyAction:""
            },
            uinfo: {},
            lotinfo: {},
            create_btn: false,
            receipt_btn: true,
            Lot_btn:false,
            print_btn: true,
            reset_btn:true,
            print_num: '',
            hasError: false,
            appVersion:"",
        },
        mounted() {
            const that = this
            window.onresize = () => {
                return (() => {
                    that.screenwidth = document.body.clientWidth
                })()
            }
        },
        computed: {
            receipt_btn() {
            // 根据表单值的变化动态计算receipt_btn的值
            return Object.values(this.searchdata).some(value => !value);
            }
        },
        methods: {
            toSerial: function () {
                if(!this.searchdata.TranQty){
                    api.toast({
                        msg: lan['palase_enter'] + lan['Tran_Qty'],
                        location: 'middle'
                    });
                    return;
                }
                var data = {};
                if(this.searchdata.SerialNum.length == 0 || this.searchdata.oldQty != this.searchdata.TranQty){
                    this.searchdata.SerialNum = []
                    var InputOurQty = processNumber(this.searchdata.TranQty, app.searchdata.NumOfDec);
                    for (let i = 0; i < InputOurQty; i++) {
                        this.searchdata.SerialNum.push({
                            'type': i+1,
                            'SerialNumber': '',
                        })
                    }
                }
               
                this.searchdata.WarehouseCode = this.searchdata.FromWarehouseCode
                this.searchdata.BinNum = this.searchdata.FromBinNum
              
                data.post = this.searchdata;
                data.index = 0;
                data.post.Lot_btn = app.Lot_btn;
                data.post.snsCheck = app.snsCheck
                data.post.index = 1;
                data.searchdata = this.searchdata;
                data.title = lan['Shelves'];
                data.frame = "sn_inventory_transfer";
                data.right = [{
                    text: lan["Scan"],
                    color: '#fff',
                }];
                console_debug(data,"sn_inventory_transfer");
                openNavWin2(data.frame, data);

            },
            blurPartNumInfo(){
                const value = this.searchdata.PartNum;
                getPartNumInfo(value)
            },
            lotFocus:function(){
                scan1()
            },
            lotBlur:function(){
                loadOnhandData(app.searchdata)
            },
            onWareQuery(){
                app.searchdata.warehouseFlag = true;
            },
            onWareScan(){
                app.searchdata.warehouseFlag = false;
            },
            onBinQuery(){
                app.searchdata.binFlag = true;
            },
            onBinScan(){
                app.searchdata.binFlag = false;
            },
            onWareQuery1(){
                app.searchdata.warehouseFlag1 = true;
            },
            onWareScan1(){
                app.searchdata.warehouseFlag1 = false;
            },
            onBinQuery1(){
                app.searchdata.binFlag1 = true;
            },
            onBinScan1(){
                app.searchdata.binFlag1 = false;
            },
            onLotQuery(){
                app.searchdata.lotFlag = true;
            },
            onLotScan(){
                app.searchdata.lotFlag = false;
            },
            housechange: function () {
                loadBinData1(this.searchdata.ToWarehoseCode);
            },
            waerChange:function(){
                loadBinData(this.searchdata.FromWarehouseCode)
            },
           
            warehouseFocus:function(){
                scan2()
            },
            binFocus:function(){
                scan3()
            },
            houseFocus:function(){
                scan4()
            },
            binFocus1:function(){
                scan5()
            },
            binChange:function(){
                app.searchdata.LotNum = "";
                loadOnhandData(app.searchdata)
            }

           
        }
    });
    apiready = function () {
        api.parseTapmode();
        server = getapi();
        app.appVersion = api.appVersion;
        api.addEventListener({ name: 'navitembtn' }, function (ret, err) {
            if (ret.type == 'left') { close_win1(); }
            if (ret.type == 'right') { scan(); }

        });
        app.vendors = get_prefs_data("Vendors");
        app.uinfo = get_user_info();
        userinfo = get_user_info();
        app.searchdata.name = userinfo.Name;

        setTimeout(function () {
            init_select();
        }, 200);
        
        api.addEventListener({
            name: 'sn_inventory_transfer'
        }, function (ret, err) {
            if(ret && ret.value){
                var snposts = ret.value;
                console.log(JSON.stringify(snposts),33333)
                app.searchdata.TranQty = snposts.TranQty;
                app.searchdata.oldQty = snposts.oldQty;
                app.searchdata.SerialNum = snposts.SerialNum;
                console.log(JSON.stringify(app.searchdata),44444)
                api.closeWin({name: 'sn_inventory_transfer'});
            }
        });
        api.addEventListener({
            name: 'infrared_scanning'
        }, function (ret, err) {
            console.log(JSON.stringify(ret));
            if (ret && ret.value && ret.value.str && is_scan == 0) {
                app.searchdata.PartNum = ret.value
                getPartNumInfo(ret.value)
            }

        });
        api.addEventListener({
            name: 'keyback',
            extra: {
                slidBackIntercept: true    
            }
        }, function (ret, err) {
            close_win1()
        });
    }
    function Resetsubmit(){
        app.searchdata.PartDescription='';
        app.searchdata.PartNum='';
        app.searchdata.FromWarehouseCode='';
        app.searchdata.FromBinNum='';
        app.searchdata.ToWarehoseCode='';
        app.searchdata.ToBinNum='';
        app.searchdata.LotNum='';
        app.searchdata.OnhandQty=0;
        app.searchdata.TranQty=0;
        app.searchdata.IUM='';
        app.searchdata.oldQty="";
        app.searchdata.is_Lot=false;
        app.searchdata.is_SerialNum=false;
        app.searchdata.SerialNum=[];
        app.searchdata.lotFlag=false;
        app.searchdata.binFlag=false;
        app.searchdata.warehouseFlag=false;
        app.searchdata.binFlag1=false;
        app.searchdata.warehouseFlag1=false;
        app.receipt_btn = false
    }
    function scan1(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.searchdata.LotNum = ret.content;
                    setTimeout(function(){
                        loadOnhandData(app.searchdata)
                    },300)
                }
            } 
        });
          
    }
    function scan2(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.searchdata.FromWarehouseCode = ret.content;
                    setTimeout(function(){
                        loadBinData(ret.content)
                    },300)
                }
            } 
        });
          
    }
    function scan3(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.searchdata.FromBinNum = ret.content;
                    setTimeout(function(){
                        loadOnhandData(ret.content)
                    },300)
                }
            } 
        });
          
    }
    function scan4(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.searchdata.ToWarehoseCode = ret.content;
                    setTimeout(function(){
                        loadBinData1(ret.content)
                    },300)
                }
            } 
        });
          
    }
    function scan5(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.searchdata.ToBinNum = ret.content;
                    
                }
            } 
        });
          
    }
    function getPartNumInfo(data){
        userinfo = get_user_info();
        var filter = "?CompID=" + userinfo.Company  + "&Site=" + userinfo.Site;
        filter += "&PartNum=" + data ;
        api.ajax({
            url: server + 'BaqSvc/WMS_PartInfo/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}  
        }, function (ret, err) {
            ajaxing = 0;
            is_scan = 0;
            console.log(JSON.stringify(ret),44444)
            hideProgress();
            if (ret && ret.value.length>0) {
                let newList = init_list(ret.value)
                console.log(JSON.stringify(newList),111111)
                app.searchdata.PartNum = newList[0].PartNum;
                app.searchdata.PartDescription = newList[0].PartDescription;
                app.searchdata.FromWarehouseCode = newList[0].WarehouseCode;
                app.searchdata.FromBinNum = newList[0].BinNum
                app.searchdata.is_SerialNum = newList[0].Part_TrackSerialNum
                app.searchdata.is_Lot = newList[0].Part_TrackLots
                app.searchdata.IUM = newList[0].Part_IUM
                // return;
                for (i in newList){
                    var ret1 = [];
                    ret1.push(newList[i]);
                    app.list = app.list.concat(ret1);
                    setTimeout(function(){
                        loadOnhandData(app.searchdata)
                        loadWarehouseCodeData()
                        loadBinData(app.searchdata.FromWarehouseCode)
                        $('#vendorselect').val(app.searchdata.FromWarehouseCode).trigger("change");
                        $('#vendorselect2').val(app.searchdata.FromBinNum).trigger("change");
                    },200)
                    console.log(JSON.stringify(app.list),55555)
                    
                    if (app.list.length > 0) {
                        app.receipt_btn = false;
                    }
                }

            }else{
                api.toast({
                    msg: lan['Part_valid_placeholder'],
                    location: 'middle'
                });
            }

        });
    }
    async function loadWarehouseCodeData() {
        userinfo = get_user_info();
        if (!userinfo.Token) {
            return;
        }
        $('.myselect1').selectpicker('destroy'); // 先销毁
        $('.myselect3').selectpicker('destroy'); // 先销毁
        app.WareHouseCodeList = [];
        await api.ajax({
            url: server + 'BaqSvc/WMS_WarehouseForPart/?CompID=' + userinfo.Company + "&Site=" + userinfo.Site +"&PartNum="+app.list[0].PartNum,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
                app.WareHouseCodeList = app.WareHouseCodeList.concat(ret.value)
                setTimeout(function () {
                    $('.myselect1').selectpicker('refresh');//在更新
                    $('.myselect3').selectpicker('refresh');//在更新
                    app.receipt_btn = false;
                }, 200)
                console.log(JSON.stringify(app.WareHouseCodeList), 22222)
            }
        });
    }
    async function loadBinData(value) {
        userinfo = get_user_info();
        app.BinNumList = []
        $('.myselect2').selectpicker('destroy'); // 先销毁
        await api.ajax({
            url: server + 'BaqSvc/WMS_WhseBin/?CompID=' + userinfo.Company + "&WarehouseCode=" + value,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {

            }
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
                app.BinNumList = app.BinNumList.concat(ret.value)
                setTimeout(function () {
                    $('.myselect2').selectpicker('refresh');//在更新
                }, 200)
                console.log(JSON.stringify(app.BinNumList), 22222)
            }

        });
    }

    async function loadBinData1(value) {
        userinfo = get_user_info();
        app.bin = []
        $('.myselect4').selectpicker('destroy'); // 先销毁
        await api.ajax({
            url: server + 'BaqSvc/WMS_WhseBin/?CompID=' + userinfo.Company + "&WarehouseCode=" + value,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {

            }
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
                app.bin = app.bin.concat(ret.value)
                setTimeout(function () {
                    $('.myselect4').selectpicker('refresh');//在更新
                    app.receipt_btn = false;
                }, 200)
                console.log(JSON.stringify(app.bin), 22222)
            }

        });
    }
    function loadOnhandData(data,i){
        userinfo = get_user_info();
        var filter = "?CompID=" + userinfo.Company  + "&Site=" + userinfo.Site;
        filter += "&PartNum=" + data.PartNum;
        filter += "&WhseCode=" + data.FromWarehouseCode;
        filter += "&Bin=" + data.FromBinNum;
        if(data.LotNum){
            filter += "&LotNum=" + data.LotNum;
        }
        console.log(filter,77777)
        api.ajax({
            url: server + 'BaqSvc/WMS_PartBinOnhand/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}  
        }, function (ret, err) {
            ajaxing = 0;
            is_scan = 0;
            console.log(JSON.stringify(ret),66666)
            hideProgress();
            if (ret && ret.value.length>0) {
                app.searchdata.OnhandQty =  processNumber(ret.value[0].PartBin_OnhandQty,data.NumOfDec);
                app.searchdata.IUM = ret.value[0].PartBin_DimCode;
                app.searchdata.LotNum = ret.value[0].PartBin_LotNum;
                app.receipt_btn = false;
            }else{
                app.searchdata.OnhandQty =  0;
                app.searchdata.IUM = "";
                app.searchdata.LotNum = "";
            }
        })
    }    
    function init_list(data) {
        var ret = [];
        for (i in data) {
            data[i].PartNum = data[i].Part_PartNum;
            data[i].PartDescription = data[i].Part_PartDescription;
            data[i].NumOfDec = data[i].UOM_NumOfDec;
            data[i].IUM = data[i].Part_IUM
            data[i].WarehouseCode = data[i].PlantConfCtrl_DefaultWhse;
            data[i].BinNum = data[i].PlantConfCtrl_DefGenBin
            data[i].OnhandQty = 0;
            data[i].TranQty = 0
            data[i].is_Lot = -1; //批号判断 -1 未查询  1 需创建 2 不需创建
            data[i].is_SerialNum = -1; //序列号判断 -1 未查询  1 需创建 2 不需创建
            if (data[i].Part_TrackLots) {
                data[i].is_Lot = 1
            } else {
                data[i].is_Lot = 2
            }
            if (data[i].Part_TrackSerialNum) {
                data[i].is_SerialNum = 1; 
            } else {
                data[i].is_SerialNum = 2; 
            }
            data[i].SerialNum = [];
            ret.push(data[i]);

        }
        return ret;
    }
    function init_select() {
        $('.myselect1').selectpicker();
        $('.myselect2').selectpicker();
        $('.myselect3').selectpicker();
        $('.myselect4').selectpicker();
    }
    function scan() {
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    // alert(ret.content);
                    app.searchdata.PartNum = ret.content
                    getPartNumInfo(ret.content)
                }

            } else {
                //alert(JSON.stringify(err));
            }
        });
    }
    function checksubmit() {
        let hasNegativeQty = false;

        for (let i = 0; i < app.list.length; i++) {
            const item = app.list[i];
            if (item.PartClass_NegQtyAction === "Stop" ) {
                if (processNumber(app.searchdata.TranQty,item.NumOfDec) > processNumber(app.searchdata.OnhandQty,item.NumOfDec)) {
                    const message = `Part: ${item.PartNum}. Warehouse: ${app.searchdata.FromWarehouseCode}. Bin: ${app.searchdata.BinNum}. This transaction will result in a negative onhand quantity for the bin.`;
                    api.confirm({
                        title: lan["Tips"],
                        msg: message,
                        buttons: ["", lan["YES"]],
                    },function (ret, err) {
                        // 用户点击了 "YES"，继续提交数据或执行相应的操作
                        // 在这里编写用户点击 "YES" 后的处理逻辑
                        });
                    hasNegativeQty = true;
                    break; // 提示一次后停止继续检查
                }
            }
        }

        if (!hasNegativeQty) {
            for (let i = 0; i < app.list.length; i++) {
                const item = app.list[i];
                if (item.PartClass_NegQtyAction === "Warn") {
                    if (processNumber(app.searchdata.TranQty,item.NumOfDec) > processNumber(app.searchdata.OnhandQty,item.NumOfDec)) {
                        const message = `This transaction will result in a negative onhand quantity for Part: ${item.PartNum}, Bin: ${app.searchdata.FromBinNum}. Do you want to continue?`;
                        api.confirm(
                        {
                            title: lan["Tips"],
                            msg: message,
                            buttons: [lan["NO"], lan["YES"], lan["Cancel"]],
                        },
                        function (ret, err) {
                            var index = ret.buttonIndex;
                            if (index === 2) {
                                submitfrom();
                                // 用户点击了 "YES"，继续提交数据或执行相应的操作
                                // 在这里编写用户点击 "YES" 后的处理逻辑
                            } else if (index === 1) {
                                // close_win();
                                // 用户点击了 "NO"，返回原页面或执行相应的操作
                                // 在这里编写用户点击 "NO" 后的处理逻辑
                            }
                        }
                        );
                        return; // 提示一次后停止继续检查
                    }
                }
            }

            submitfrom();
        }
    }
   
    function submitfrom() {
        if(!app.searchdata.ToWarehoseCode){
            api.toast({
                msg: lan['WareHouseCode_placeholder'],
                location: 'middle'
            });
            return;
        }
        if(!app.searchdata.ToBinNum){
            api.toast({
                msg: lan['BinNum_placeholder'],
                location: 'middle'
            });
            return;
        }
        if(app.searchdata.is_SerialNum && app.searchdata.SerialNum.length == 0){
            api.toast({
                msg: lan['Serialnum_placeholder'],
                location: 'middle'
            });
            return;
        }
        if(app.searchdata.FromWarehouseCode == app.searchdata.ToWarehoseCode && app.searchdata.FromBinNum == app.searchdata.ToBinNum){
            api.toast({
                msg: lan['destination_placeholder'],
                location: 'middle'
            });
            return; 
        }
        postlist = [];

        if(ajaxing){return;}showProgress(lan['Loading']);
        console_debug(app.list, 'submitfrom');
        postlist.push(app.searchdata);

        var postrows = [];
        for (let i in postlist) {
            var item = postlist[i];
            //submit_transfer(data1, app.list[i]);

            var row = {
                "CompanyID": userinfo.Company,
                "PlantID": userinfo.Site,
                "UserName": userinfo.Name,
                "Password": userinfo.password,
                "TranDate": app.searchdata.ArrivedDate,
                "PartNum": app.searchdata.PartNum,
                "FromWarehouseCode": app.searchdata.FromWarehouseCode,
                "FromBinNum": app.searchdata.FromBinNum,
                "TranQty": app.searchdata.TranQty,
                "UM": app.searchdata.IUM,
                "ToWarehoseCode": app.searchdata.ToWarehoseCode,
                "ToBinNum": app.searchdata.ToBinNum,
                "LotNum": app.searchdata.LotNum,
                "IUM": app.searchdata.IUM,
            }

            var arr = [];
            if(postlist[i].SerialNum.length>0){
                var SerialNum = postlist[i].SerialNum;
                for(k in SerialNum){
                    var row1 = {};
                    row1.SerialNumber = SerialNum[k].SerialNumber;
                    arr.push(row1);
                }
            }
            if(arr.length>0){
                row.SelectedSerialNumbers = arr;
            }
            postrows.push(row);
        }
        // return
        console.log(JSON.stringify(postrows),111111)
        // return
        let data = [];
        for (i in postrows) {
            submit_transfer(postrows[i], i);
        } 
        
    }

    //关闭取消事件
    function close_win1() {
        api.confirm({
            title: lan['Tips'],
            msg: lan['attribute_cancel_tips'],
            buttons: [lan['NO'], lan['YES'], lan['Cancel']]
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 2) {
                checksubmit();
            } else if (index == 1) {
                close_win();
            }
        });

    }
    function submit_transfer(item,ind) {
        let index = []
        let datas = []
        datas.push(item)
        var data1 = {
            "CompanyID": userinfo.Company,
            "PlantID": userinfo.Site,
            "UserName": userinfo.Name,
            "Password": userinfo.password,
            "Data": JSON.stringify(datas)
        }
       

        api.ajax({
            url: wmsserver + 'transfer/',
            method: 'post',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {
                body: create_submit_data(data1)
            }
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);
            console.log(JSON.stringify(ret),11111)
            console.log(JSON.stringify(err),22222)
            if (ret && ret.code == 1) {
                hideProgress();
                api.alert({
                    title: lan['Tips'],
                    msg: lan['Submitted_successfully']
                }, function (ret, err) {
                    app.receipt_btn = true
                    app.reset_btn = false
                });
                
            } else {
                hideProgress();
                app.receipt_btn = true
                errMassage(ret.msg)
            }

        });
    }

   

 
    function getOnhandQty(item, index, resolve, reject) {
        console.log(JSON.stringify(item),33333)
        api.ajax({
            url: server + 'BaqSvc/AMS_PartBinOnHand/?CompanyID=' + userinfo.Company +
                '&FromBin=' + item.FromBinNum + '&FromWhse=' + item.FromWarehouseCode +
                '&PartNum=' + item.PartNum + '&Site=' + userinfo.Site + '&LotNum=' + item.LotNum,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}
        }, function (ret, err) {
            console.log(JSON.stringify(ret),44444)
            console.log(JSON.stringify(err),66666)
            if (ret && ret.value) {
                if(ret.value.length > 0){
                    console.log(JSON.stringify(ret.value[0]),44444)
                    if (item.TranQty > processNumber(ret.value[0].PartBin_OnhandQty,item.NumOfDec)) {
                        hideProgress()
                        api.toast({
                            msg: lan['Negative_Inventory_placeholder'],
                            location: 'middle'
                        });
                        app.hasError = true; // 设置错误标志为true
                    }
                }
                if(ret.value.length == 0){
                    hideProgress()
                    api.toast({
                        msg: lan['Negative_Inventory_placeholder'],
                        location: 'middle'
                    });
                    app.hasError = true; 
                }
              
            }else{
                hideProgress()
                errMassage(ret.msg)
                app.hasError = true; // 设置错误标志为true
            }
            // 无论成功或失败，都要调用 resolve 或 reject
            resolve();
        });
    }
   






</script>

</html>